package com.finals.finalsscreen.util;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;

import com.finals.finalsscreen.MainActivity;
import com.finals.finalsscreen.R;

public class NotificationUtil {

	Service mService;

	android.app.Notification mNotification;

	public NotificationUtil(Service mService) {
		this.mService = mService;
	}

	public void InitData(String title, String content) {
		if (TextUtils.isEmpty(title)) {
			title = "";
		}
		if (TextUtils.isEmpty(content)) {
			content = "";
		}
		Intent intent = new Intent(mService, MainActivity.class);
		intent.setAction(Intent.ACTION_MAIN);
		intent.addCategory(Intent.CATEGORY_LAUNCHER);

		PendingIntent mIntent = PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mService);
		mBuilder.setContentTitle(title)
		// Finals 设置内容
				.setContentText(content)
				// Finals 设置小图标
				.setSmallIcon(R.drawable.ic_launcher)
				// 设置Intent
				.setContentIntent(mIntent)
				// 设置什么时候
				.setWhen(System.currentTimeMillis());
		mNotification = mBuilder.build();
	}

	public void Notification() {
		if (mService != null) {
			mService.startForeground(1, mNotification);
		}
	}

	public void CancelNotification() {
		if (mService != null) {
			mService.stopForeground(true);
		}
	}
}
